package com.googlecode.openrtp.spi.rtcp;

/**
 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 * |V  |P|    RC   |   PT=SR=200   |             length            |
 *
 * @author jocke
 */
public class RtcpHeaderPacket {
    
    public static final int PACKET_LENGTH = 4;
    
    public static final int FINAL_VERSION = 2;
    
    /* Version two bit should always be 2 */
    private int v;
    
    /* Padding if used 1 bit*/
    private int p;
    
    /*   
     * The number of reception report blocks contained in this packet.  A
     * value of zero is valid. 5 bits
     */
     private int rc;
     
     /*Type 8 bits */
     private int pt;
     
     /*
      * The length of this RTCP packet in 32-bit words minus one,
      * including the header and any padding.  (The offset of one makes
      * zero a valid length and avoids a possible infinite loop in
      * scanning a compound RTCP packet, while counting 32-bit words
      * avoids a validity check for a multiple of 4.) 16 bits*/
     private int length;

     private RtcpHeaderPacket(int v, int p, int rc, int pt, int length) {
         this.v = v;
         this.p = p;
         this.rc = rc;
         this.pt = pt;
         this.length = length;
     }
     
    public static RtcpHeaderPacket create(int v, int p, int rc, int pt, int length) {
        return new RtcpHeaderPacket(v, p, rc, pt, length);
    }
    
    
     public int getV() {
     return v;
     }

     public int getP() {
     return p;
     }

     public int getRc() {
     return rc;
     }

     public int getPt() {
     return pt;
     }

    public int getLength() {
        return length;
    }
    
    public int wordBoundry() {
        return length * 4;
    }

    @Override
    public String toString() {
        return "RtcpHeaderPacket{" + "v=" + v + ", p=" + p + ", rc=" + rc + ", pt=" + pt + ", length=" + length + '}';
    }

    
    
    @Override
    public int hashCode() {
        int hash = 3;
        hash = 41 * hash + this.v;
        hash = 41 * hash + this.p;
        hash = 41 * hash + this.rc;
        hash = 41 * hash + this.pt;
        hash = 41 * hash + this.length;
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final RtcpHeaderPacket other = (RtcpHeaderPacket) obj;
        if (this.v != other.v) {
            return false;
        }
        if (this.p != other.p) {
            return false;
        }
        if (this.rc != other.rc) {
            return false;
        }
        if (this.pt != other.pt) {
            return false;
        }
        if (this.length != other.length) {
            return false;
        }
        return true;
    }
    
    public static final class PT {

        public static final int SENDER_REPORT = 200;
        public static final int RECEIVER_REPORT = 201;
        public static final int SOURCE_DESC = 202;
        public static final int BYE = 203;
    }
}
